package com.yike.user.service.impl;

import com.yike.user.entity.UserAuthorize;
import com.yike.user.mapper.UserAuthorizeMapper;
import com.yike.user.service.UserAuthorizeService;
import com.yike.user.param.UserAuthorizePageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户授权表 服务实现类
 *
 * @author Sakura
 * @since 2024-08-22
 */
@Slf4j
@Service
public class UserAuthorizeServiceImpl extends BaseServiceImpl<UserAuthorizeMapper, UserAuthorize> implements UserAuthorizeService {

    @Autowired
    private UserAuthorizeMapper userAuthorizeMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveUserAuthorize(UserAuthorize userAuthorize) throws Exception {
        return super.save(userAuthorize);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateUserAuthorize(UserAuthorize userAuthorize) throws Exception {
        return super.updateById(userAuthorize);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteUserAuthorize(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<UserAuthorize> getUserAuthorizePageList(UserAuthorizePageParam userAuthorizePageParam) throws Exception {
        Page<UserAuthorize> page = new PageInfo<>(userAuthorizePageParam, OrderItem.desc(getLambdaColumn(UserAuthorize::getCreateTime)));
        LambdaQueryWrapper<UserAuthorize> wrapper = new LambdaQueryWrapper<>();
        IPage<UserAuthorize> iPage = userAuthorizeMapper.selectPage(page, wrapper);
        return new Paging<UserAuthorize>(iPage);
    }

}
